<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
<head>
<base target="_self" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="Content-Type"
	content="application/x-www-form- urlencoded; charset=UTF-8" />
<title>添加员工信息</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<link rel="Stylesheet" type="text/css"
	href="<c:url value="/static/css/jquery.ui.css"/>" />
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/showMsg.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/listBox/jquery.clever.listbox.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>

<script type="text/javascript">
	$.extend($.fn.validatebox.defaults.rules, {
		usernameCheck : {
			validator : function(value) {
				var return_flag;
				$.ajax({
					async : false,
					url : "<c:url value='/user/checkUserName.do'/>" + "?value="
							+ value,
					type : "post",
					success : function(data) {
						var dataLeft = data;
						if (typeof (dataLeft) == 'string' && dataLeft != '') {
							dataLeft = JSON.parse(dataLeft);
						}
						if (dataLeft.success) {
							return_flag = true;
						} else {
							return_flag = false;
						}
					}
				});
				return return_flag;
			},
			message : '系统已存在该用户名！'
		}
	});

	$.extend($.fn.validatebox.defaults.rules, {
		realNameCheck : {
			validator : function(value) {
				var return_flag;
				$.ajax({
					async : false,
					url : "<c:url value='/user/checkRealName.do'/>" + "?value="
							+ value,
					type : "post",
					success : function(data) {
						var dataLeft = data;
						if (typeof (dataLeft) == 'string' && dataLeft != '') {
							dataLeft = JSON.parse(dataLeft);
						}
						if (dataLeft.success) {
							return_flag = true;
						} else {
							return_flag = false;
						}
					}
				});
				return return_flag;
			},
			message : '系统已存在该用户名！'
		}
	});

	$.extend($.fn.validatebox.defaults.rules, {
		phoneCheck : {
			validator : function(value) {
				var return_flag;
				$.ajax({
					async : false,
					url : "<c:url value='/user/checkPhone.do'/>" + "?value="
							+ value,
					type : "post",
					success : function(data) {
						var dataLeft = data;
						if (typeof (dataLeft) == 'string' && dataLeft != '') {
							dataLeft = JSON.parse(dataLeft);
						}
						if (dataLeft.success) {
							return_flag = true;
						} else {
							return_flag = false;
						}
					}
				});
				return return_flag;
			},
			message : '系统已存在该电话号码！'
		}
	});
	//获取data 数据
	$(document).ready(function() {
		initDate();
	});

	//添加信息按钮响应函数
	function addUser() {
		$('#AddUserForm').form('submit', {
			url : '<c:url value='/userforsup/saveUserForSupShopUser.do'/>', //查询提交路径
			onSubmit : function()//提交按钮相应函数
			{
				var password = $('#password').val();
				var password2 = $('#password2').val();
				if (password == null) {
					$.messager.alert("错误", "密码不能为空!", 'error');
					return false;
				} else if (password != password2) {
					$.messager.alert("错误", "密码两次输入不同!", 'error');
					return false;
				}

				return $('#AddUserForm').form('validate');
			},
			success : function(data) {
				data = eval('(' + data + ')');
				if (data.success) {
					$.messager.alert('系统提示', '新增成功', 'info', function() {
		                window.opener.window.teaNew('listDisplay2');
						window.close();
					});
				} else {
					$.messager.alert("提示", data.msg, 'warning');
				}
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});

	}
	function initDate() {
		$('#province').combobox({
			url : '<c:url value='/user/pullDownProvince.do'/>',
			editable : true, //不可编辑状态  
			cache : false,
			panelHeight : '150',
			valueField : 'areaid',
			textField : 'name',
			required : true,
			onChange : function(newValue, oldValue) {
				$.post('<c:url value='/user/pullDownCity.do'/>', {
					parentId : newValue
				}, function(data) {
					$('#city').combobox("clear").combobox('loadData', data);
				}, 'json');
			}
		});
		$('#city').combobox({
			valueField : 'areaid',
			textField : 'name',
			editable : false,
			url : '<c:url value='/user/pullDownCity.do'/>',
			onChange : function(newValue, oldValue) {
				$.post('<c:url value='/user/pullDownCountry.do'/>', {
					parentId : newValue
				}, function(data) {
					$('#country').combobox("clear").combobox('loadData', data);
				}, 'json');
			}
		});
		$('#country').combobox({
			url : '<c:url value='/user/pullDownCountry.do'/>',
			valueField : 'areaid',
			textField : 'name',
			editable : false
		});
	}

	function searchInfo() {
		$('#searchForm').form('submit', {
			url : '<c:url value='/user/userlevelChina.do'/>', //查询提交路径
			onSubmit : function()//提交按钮相应函数
			{
				return $('#searchForm').form('validate');
			},
			success : function(data) {
				data = eval("(" + data + ")");
				var left = $('#left').listbox();
				var items = left.getSelected();
				left.removeRange(items);

				var right = $('#right').listbox();
				var itemsr = right.getSelected();
				right.removeRange(itemsr);

				$('#left').listbox().reload({
					data : data,
					ajaxsettings : {
						data : {
							id : 'a'
						}
					}
				});
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});
	}
</script>
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
</head>

<body>
	<table width="90%" align="center">
		<tr></tr>
		<tr>
			<td>

				<div style="height: auto; background: #fafafa; padding: 5px;"
					class="easyui-panel" title="添加用户信息" iconCls="icon-save"
					collapsible="true" minimizable="false" maximizable="false"
					closable="false">

					<form id="AddUserForm" name="AddUserForm" method="post">
						<table cellpadding="5">
							<tr>
								<td>登录用户名:</td>
								<td><input class="easyui-textbox" type="text"
									data-options="validType:'usernameCheck'" name="userName"
									required="true" /></td>
								<td>姓名:</td>
								<td><input class="easyui-textbox" type="text"
									name="realName" required="true" validType="length[1,100]" /></td>
							</tr>
							<tr>
								<td>密码:</td>
								<td><input class="easyui-textbox" type="password"
									id="password" required="true" validType="length[1,100]"
									name="password" /></td>
								<td>确认密码:</td>
								<td><input class="easyui-textbox" type="password"
									id="password2" required="true" validType="length[1,100]"
									name="password2" /></td>
							</tr>
							<tr>
								<td>电话:</td>
								<td><input class="easyui-numberbox" type="userPhone"
									data-options="validType:'phoneCheck'" name="userPhone"
									required="true" /></td>
								<td>邮箱:</td>
								<td><input class="easyui-textbox" type="email" name="email"
									validType="email" validType="length[1,100]" /></td>
							</tr>
							<tr>
								<td>是否有效:</td>
								<td><select class="easyui-combobox" name="isActive">
										<option value="0">有效</option>
										<option value="1">失效</option>
								</select></td>
							</tr>

							<tr>
								<td>省:</td>
								<td><input class="easyui-combobox" name="province"
									id="province" required="true" /></td>
							</tr>

							<tr>
								<td>市:</td>
								<td><input class="easyui-combobox" name="city" id="city"
									required="true" /></td>
							</tr>

							<tr>
								<td>区:</td>
								<td><input class="easyui-combobox" name="country"
									id="country" required="true" /></td>
							</tr>
						</table>
						<br> <br> <a class="easyui-linkbutton"
							onclick="addUser()">添加</a>
					</form>

				</div>
			</td>
		</tr>
	</table>

</body>
</html>